package com.digitalchina.lxnsy.viewholder;

import androidx.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.MyFarmListVO;
import com.digitalchina.lxnsy.interfaces.IDeleteBack;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;


/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2017/10/27 13:10
 * 修改备注：
 * ================================================
 */

public class MyFarmListHolder extends BaseViewHolder<MyFarmListVO> {

    private TextView tvName;
    private TextView tvArea;
    private TextView tvType;
    private ImageView imageView;

    private IDeleteBack iDeleteBack;



    public MyFarmListHolder(ViewGroup parent,IDeleteBack iDeleteBack) {
        super(parent, R.layout.item_my_farm_list);
        this.iDeleteBack = iDeleteBack;
        tvName = $(R.id.tv_name);
        tvArea = $(R.id.tv_area);
        tvType = $(R.id.tv_type);
        imageView = $(R.id.iv_delete);

    }

    @Override
    public void setData(final MyFarmListVO data) {
        super.setData(data);

        String array[] = data.getTypeName().split("/");
        tvName.setText(array[array.length - 1] + "");
        tvArea.setText(data.getEstateNumber() + "");
        tvType.setText(data.getTypeName() + "");

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new MaterialDialog.Builder(getContext())
                        .title("提示")
                        .content("确定要删除该条信息？")
                        .positiveText("删除")
                        .negativeText("取消")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                iDeleteBack.clickOk(getAdapterPosition());
                            }
                        })
                        .show();
            }
        });
    }

}
